package com.xywh.emergency_outbound.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.utils.LogUtils;
import com.xywh.emergency_outbound.R;
import com.xywh.emergency_outbound.mvp.ui.db.DbController;
import com.xywh.emergency_outbound.mvp.ui.entity.Tab1;
import com.xywh.emergency_outbound.mvp.ui.entity.Tab3;

import org.simple.eventbus.EventBus;

import java.util.List;

import me.jessyan.armscomponent.commonres.view.amount_view.AmountView;


public class Tab3Adapter extends BaseQuickAdapter<Tab3.DataBean, BaseViewHolder> {

    private Context mContext;
    private DbController mDbController;
    private IItemDelete mIItemDelete;

    public Tab3Adapter(Context context, @Nullable List<Tab3.DataBean> data, DbController dbController, IItemDelete iItemDelete) {
        super(R.layout.item_tab3, data);
        this.mContext = context;
        this.mDbController = dbController;
        this.mIItemDelete = iItemDelete;
    }

    @Override
    protected void convert(BaseViewHolder helper, Tab3.DataBean item) {
        //GlideUtil.loadImage(mContext,item.getImg(),helper.getView(R.id.img_head));
        helper.setText(R.id.tv_title, item.getMaterialName());
        helper.setText(R.id.tv_outbound_warehouse, "出库仓库：" + item.getStoreName());
//        helper.setText(R.id.tv_required_quantity, "需求数量：" + item.getStoreNum());
        AmountView amountView = helper.getView(R.id.amount_view);
        amountView.setOnAmountChangeListener(null);
        amountView.setGoods_storage(item.getStoreNum());
//        amountView.setEtAmount(item.getStoreNum());
        amountView.setEtAmount(1);
        amountView.setOnAmountChangeListener(new AmountView.OnAmountChangeListener() {
            @Override
            public void onAmountChange(View view, double amount) {
                item.setStoreNum(amount);
                LogUtils.debugEInfo("itemStoreNum=" + item.getStoreNum());
                mDbController.update(item);
            }
        });

        helper.setOnClickListener(R.id.img_del, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Tab1.DataBean dataBean = new Tab1.DataBean();
                    dataBean.setMaterialName(item.getMaterialName());
                    dataBean.setStoreName(item.getStoreName());
                    dataBean.setStoreId(item.getStoreId());
                    mDbController.delete(dataBean);
                    mIItemDelete.itemDelete();


                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
    }

    public interface IItemDelete {
        void itemDelete();
    }


}
